package com.iwomy.secureplat.platform.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.secureplat.common.core.util.R;
import com.iwomy.secureplat.common.excel.annotation.ResponseExcel;
import com.iwomy.secureplat.platform.dto.SensorTransmissionDataDto;
import com.iwomy.secureplat.platform.excel.SensorTransmissionExcel;
import com.iwomy.secureplat.platform.service.RealTimeDataService;
import com.iwomy.secureplat.platform.transmission.entity.SensorTransmissionData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 实时数据表
 *
 * @author pig
 * @date 2023-08-31 09:28:08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/realTimeData")
@Tag(description = "realTimeData", name = "实时数据表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class RealTimeDataController {

	private final RealTimeDataService realTimeDataService;

	/**
	 * 通过imei查询一条实时数据
	 *
	 * @param imei imei
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{imei}")
	public R getByImei(@PathVariable("imei") String imei) {
		return R.ok(realTimeDataService.getOneByImei(imei));
	}

	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	public R page(@ParameterObject Page page,@ParameterObject SensorTransmissionDataDto sensorTransmissionDataDto) {
		return R.ok(realTimeDataService.page(page,sensorTransmissionDataDto));
	}

	@Operation(summary = "设备详情属性曲线", description = "设备详情属性曲线")
	@GetMapping("/attributeCurve")
	public R attributeCurve(@ParameterObject SensorTransmissionDataDto sensorTransmissionDataDto) {
		return R.ok(realTimeDataService.attributeCurve(sensorTransmissionDataDto));
	}


	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/export")
	@ResponseExcel
	public List<SensorTransmissionExcel> export(@ParameterObject Page page, @ParameterObject SensorTransmissionDataDto sensorTransmissionDataDto) {
		List<SensorTransmissionData> records = realTimeDataService.page(page, sensorTransmissionDataDto).getRecords();
		return  BeanUtil.copyToList(records, SensorTransmissionExcel.class);
	}



}